package com.mingserve.raw.domain.dto;

import com.alibaba.fastjson2.annotation.JSONField;
import com.mingserve.common.core.utils.SignalUtils;
import lombok.Data;

/**
 * 测点原始数据
 *
 * @author lvwshuai
 */
@Data
public class RawDataDto
{
    /**
     * x点值
     */
    private double[] accX;
    /**
     * y点值
     */
    private double[] accY;
    /**
     * z点值
     */
    private double[] accZ;
     /**
     * 采集间隔
     */
    private double[] accT;
    /**
     * x点值
     */
    private double[] velX;
    /**
     * y点值
     */
    private double[] velY;
    /**
     * z点值
     */
    private double[] velZ;

    /**
     * 传感器型号
     */
    @JSONField(name = "Model")
    private String model;
    /**
     * 传感器编码
     */
    @JSONField(name = "ChipID")
    private String chipID;

    /**
     * 采集时间戳 必传
     */
    @JSONField(name = "Timestamp")
    private Long timestamp;
    /**
     * 采样频率(Hz) 必传
     */
    @JSONField(name = "VibSampleFreq")
    private Integer vibSampleFrequency;
    /**
     * 物体温度(°C)
     */
    @JSONField(name = "ObjectTemp")
    private Double objectTemperature;
    /**
     * 倍数 accX/gain 获得加速度的浮点值
     */
    @JSONField(name = "Gain")
    private Integer gain;

    @JSONField(name = "FftAccX")
    private Double[] accFeatureX;
    @JSONField(name = "FftAccY")
    private Double[] accFeatureY;
    @JSONField(name = "FftAccZ")
    private Double[] accFeatureZ;

    @JSONField(name = "FftVelX")
    private Double[] velFeatureX;
    @JSONField(name = "FftVelY")
    private Double[] velFeatureY;
    @JSONField(name = "FftVelZ")
    private Double[] velFeatureZ;


    // -------以下字段已废除-------
    /**
     * 量程(g)
     */
    @JSONField(name = "VibFullScaleUse")
    private Double vibFullScaleUse;

    /**
     * 传感器精度
     */
    @JSONField(name = "AdcBits")
    private Double adcBits;

    /**
     * 数据长度
     */
    public int getLength()
    {
        return getAccX() != null ? getAccX().length : getAccY() != null ? getAccY().length : getAccZ() != null ? getAccZ().length : getVelX() != null ? getVelX().length : getVelY() != null ? getVelY().length : getVelZ() != null ? getVelZ().length : 0;
    }

    /**
     * 处理原始加速度数据
     *
     * @param rawDataDto
     */
    public static void processRawAcc(RawDataDto rawDataDto)
    {
        if (rawDataDto.getGain() != null) {
            // acc信息带倍数的，除下倍数
            rawDataDto.setAccX(SignalUtils.vibDivideGain(rawDataDto.getAccX(), rawDataDto.getGain()));
            rawDataDto.setAccY(SignalUtils.vibDivideGain(rawDataDto.getAccY(), rawDataDto.getGain()));
            rawDataDto.setAccZ(SignalUtils.vibDivideGain(rawDataDto.getAccZ(), rawDataDto.getGain()));
        } else if (rawDataDto.getAdcBits() != null && rawDataDto.getVibFullScaleUse() != null) {
            // 通过传感器精度、量程计算加速度
            rawDataDto.setAccX(SignalUtils.vibToG(rawDataDto.getAdcBits(), rawDataDto.getVibFullScaleUse(), rawDataDto.getAccX()));
            rawDataDto.setAccY(SignalUtils.vibToG(rawDataDto.getAdcBits(), rawDataDto.getVibFullScaleUse(), rawDataDto.getAccY()));
            rawDataDto.setAccZ(SignalUtils.vibToG(rawDataDto.getAdcBits(), rawDataDto.getVibFullScaleUse(), rawDataDto.getAccZ()));
        }
    }
}